use std::{env, io};
use dotenv::dotenv;
use sqlx::mysql::MySqlPoolOptions;
use sqlx::Row;

#[actix_rt::main]
async fn main() -> io::Result<()> {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL")
        .expect("DATABASE_URL 没有在.env 文件里设置");

    let db_pool = MySqlPoolOptions::new()
        .connect(&database_url)
        .await
        .unwrap();

    let special = sqlx::query(
        "select book_id, book_desc,data from special limit 5"
    )
    .fetch_all(&db_pool)
    .await
    .unwrap();

    for row in special.iter() {
        println!("{},{}", row.get::<i32, &str>("book_id"),row.get::<String, &str>("book_desc"));
    }

    // println!("{:?}",special);

    // let mut special_list = vec![];

    // for row in special {
    //     println!("{}",row.book_id);
    //     println!("{}",row.book_desc);
    // }

    Ok(())
}
